<?php
class Sync_date_model extends CI_Model
{

    public function __construct()
    {
        parent::__construct();
        // 加载数据库
        $this->load->database();
    }

    public function insert($data) {
        
        // 使用 insert 方法将数据插入到数据库表中
        return $this->db->insert('tw_lucky_cat.sync_date', $data);
    }

    public function maxDate($platform)
    {
        $this->db->select("*");
        $this->db->from("tw_lucky_cat.sync_date");
        
        $this->db->where('platform', $platform);
        $this->db->order_by('date', 'DESC');
        
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->first_row()->date;
        }
        return false;
    }

    public function selectByDate($date, $platform)
    {
        $this->db->select("*");
        $this->db->from("tw_lucky_cat.sync_date");
        
        $this->db->where('date', $date);
        $this->db->where('platform', $platform);
        
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->first_row();
        }
        return false;
    }
}